/**
 * CityMapper.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2013年8月14日
 */
package com.pshare.artemis.basic.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.pshare.framework.mapper.BaseMapper;
import com.pshare.artemis.basic.bean.City;

@Repository
public interface CityMapper extends BaseMapper<Integer, City> {

	@Select("select id, province_id, name, code from tbl_base_city")
	public List<City> queryAll();
	
	@Select("select id, province_id, name, code from tbl_base_city where province_id = #{provinceId}")
	public List<City> queryByProvinceId(@Param("provinceId") Integer provinceId);
	
	@Select("select name from tbl_base_city where id = #{id}")
	public String getNameById(@Param("id") Integer id);
	
	@Select("select province_id from tbl_base_city where id = #{id}")
	public Integer getProvinceIdByCityId(@Param("id") Integer id);
	
	/**
	 * 根据ID读取城市信息
	 * @param id
	 * @return City
	 */
	@Select("select * from tbl_base_city where id = #{id}")
	public City get(@Param("id") Integer id);
	
	/**
	 * 根据名称模糊查找市ID
	 * @param name
	 * @return Integer
	 */
	@Select("select id from tbl_base_city where name like #{name} '%' ")
	public Integer findIdByName(@Param("name") String name);
	
	/**
	 * 根据名称模糊查找城市
	 * @param name
	 * @return City
	 */
	@Select("select * from tbl_base_city where name like #{name} '%' ")
	public City findByName(@Param("name") String name);
	
	/**
	 * 根据名称完全匹配查找城市ID
	 * @param name
	 * @return Integer
	 */
	@Select("select id from tbl_base_city where name = #{name} ")
	public Integer getIdByName(@Param("name") String name);
}
